package com.gis.servlet.notice;

import com.gis.bean.Notice;
import com.gis.dao.NoticeDao;
import com.gis.util.PageResult;
import com.gis.util.ResponseUtil;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author t-zhaoheng
 * @since 2022/4/19
 */
@WebServlet("/notice/page")
public class PageNoticeServlet extends HttpServlet {

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    String pageSize = req.getParameter("rows");
    if(pageSize == null) {
      pageSize = "5";
    }
    String pageNum = req.getParameter("page");
    if(pageNum == null) {
      pageNum = "1";
    }
    Integer size = Integer.parseInt(pageSize);
    Integer num = Integer.parseInt(pageNum);

    PageResult<Notice> pageResult = NoticeDao.getInstance().page(size, num);
    ResponseUtil.writePage(resp, pageResult);
  }

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    doGet(req, resp);
  }
}
